package com.wfs.myapp.repository.bk;

import com.wfs.myapp.entity.domain.bk.BkDish;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface DishRepository extends JpaRepository<BkDish, Long> {

    @Query(nativeQuery = true, value = " SELECT count(1) FROM bk_dish where name like CONCAT('%', :name, '%') ")
    Long findCountByName(String name);
    @Query(nativeQuery = true, value = " SELECT * FROM bk_dish where name like CONCAT('%', :name, '%') ")
    List<BkDish> findAllByName(String name);

    @Query(nativeQuery = true, value = " SELECT count(1) FROM bk_dish where user_id = :userId")
    long countByUserId(Long userId);

    @Query(nativeQuery = true, value = " SELECT * FROM bk_dish where user_id = :userId  order by created_time limit :page, :size")
    List<BkDish> findAllByUserId(Long userId, Integer page, Integer size);
}




